
cd "`c(pwd)'"   // Set working directory to wherever the user placed "replication_package"

* Define global paths relative to the main directory
global main_dir "`c(pwd)'"
global data_dir "$main_dir/data_analysis"
global rawdata_dir "$main_dir/data_raw"
global tables_dir "$main_dir/tables"

* Load data
cd "$data_dir/"
use master1_data, clear

*******************************************************************************
* VARIABLE CREATION I
gen link_year=year(linkdt)
gen age=year - link_year
gen log_age=log(1+age)
gen log_at=log(1+at)
gen log_sale=log(1+sale)
gen profitability = oibdp/at
replace profitability = 0 if ppent==. & at!=.
replace pstkl=0 if pstkl==.
gen mktvalue=(csho*prcc_f)+dlc+dltt
gen mkt_book=mktvalue/at
gen xrd2=xrd
replace xrd2=0 if xrd==.
gen xrd2at=xrd2/at
gen num_pat_filing2=num_pat_filing
replace num_pat_filing2=0 if num_pat_filing2==.
gen numpat2at=num_pat_filing2/at
gen valtot_pat_filing2=valtot_pat_filing
replace valtot_pat_filing2=0 if valtot_pat_filing2==.
gen valpat2at=valtot_pat_filing2/at
replace odn_connection=0 if odn_connection==.
replace codn_connection=0 if codn_connection==.
replace other_connection=0 if other_connection==.
gen oddensity4_ODN=oddensity4
replace oddensity4_ODN=0 if odn_connection==0 & oddensity4!=.
gen oddensity4_CODN=oddensity4
replace oddensity4_CODN=0 if codn_connection==0 & oddensity4!=.
gen oddensity4_ODNOTHER=oddensity4
replace oddensity4_ODNOTHER=0 if odn_connection==0 & oddensity4!=.
replace oddensity4_ODNOTHER=oddensity4 if other_connection==1 
*******************************************************************************
* LAGGED VARIABLES
sort gvkey year
bys gvkey: gen oddensity4l1=oddensity4[_n-1] if oddensity4[_n-1]!=.
bys gvkey: gen oddensity2_4l1=oddensity2_4[_n-1] if oddensity2_4[_n-1]!=.
bys gvkey: gen odfocal4l1=odfocal4[_n-1] if odfocal4[_n-1]!=.
bys gvkey: gen oddensity4_ODNl1=oddensity4_ODN[_n-1] if oddensity4_ODN[_n-1]!=.
bys gvkey: gen oddensity4_CODNl1=oddensity4_CODN[_n-1] if oddensity4_CODN[_n-1]!=.
bys gvkey: gen oddensity4_ODNOTHERl1=oddensity4_ODNOTHER[_n-1] if oddensity4_ODNOTHER[_n-1]!=.
bys gvkey: gen odn_connectionl1=odn_connection[_n-1] if odn_connection[_n-1]!=.
bys gvkey: gen codn_connectionl1=codn_connection[_n-1] if codn_connection[_n-1]!=.
bys gvkey: gen other_connectionl1=other_connection[_n-1] if other_connection[_n-1]!=.
bys gvkey: gen popoddensity4l1=popoddensity4[_n-1] if popoddensity4[_n-1]!=.
bys gvkey: gen atl1=at[_n-1] if at[_n-1]!=.
bys gvkey: gen agel1=age[_n-1] if age[_n-1]!=.
bys gvkey: gen salel1=sale[_n-1] if sale[_n-1]!=.
bys gvkey: gen profitabilityl1=profitability[_n-1] if profitability[_n-1]!=.
bys gvkey: gen mkt_bookl1=mkt_book[_n-1] if mkt_book[_n-1]!=.
bys gvkey: gen xrd2l1=xrd2[_n-1] if xrd2[_n-1]!=.
bys gvkey: gen log_atl1=log_at[_n-1] if log_at[_n-1]!=.
bys gvkey: gen log_agel1=log_age[_n-1] if log_age[_n-1]!=.
bys gvkey: gen log_salel1=log_sale[_n-1] if log_sale[_n-1]!=.
bys gvkey: gen profitabilityf1=profitability[_n+1]
bys gvkey: gen mkt_bookf1=mkt_book[_n+1]
bys gvkey: gen COWtn4l1=COWtn4[_n-1] if COWtn4[_n-1]!=.
bys gvkey: gen ISStreattn4l1=ISStreattn4[_n-1] if ISStreattn4[_n-1]!=.

*******************************************************************************
* WINSORIZING
sort year
winsor2 oddensity4 oddensity2_4 oddensity4l1 oddensity2_4l1 odfocal4 odfocal4l1 popoddensity4 popoddensity4l1 oddensity4_ODN oddensity4_CODN oddensity4_ODNOTHER oddensity4_ODNl1 oddensity4_CODNl1 oddensity4_ODNOTHERl1  xrd2at numpat2at valpat2at tsim4 prodmktfluid profitability mkt_book profitabilityf1 mkt_bookf1 log_age log_at log_sale log_atl1 agel1 log_agel1 mkt_bookl1 at COWtn4 COWtn4l1 ISStreattn4 ISStreattn4l1, cuts(5 95) by(year)

*******************************************************************************
* DROP FINANCIALS AND UTILITIES AND NEGATIVE SALES (or assets)
keep if sale>1 & at>1
destring sic, replace
gen financials=.
replace financials=0 if sic!=.
replace financials=1 if sic>=6000 & sic<=6999
gen utilities=.
replace utilities=0 if sic!=.
replace utilities=1 if sic>=4900 & sic<=4999
drop if financials==1
drop if utilities==1

*******************************************************************************
* STANDARDIZING 
egen oddensity4_wz =std(oddensity4_w)
egen oddensity4l1_wz =std(oddensity4l1_w)
egen oddensity2_4_wz =std(oddensity2_4_w)
egen oddensity2_4l1_wz =std(oddensity2_4l1_w)
egen oddensity4_ODN_wz =std(oddensity4_ODN_w)
egen oddensity4_ODNl1_wz =std(oddensity4_ODNl1_w)
egen oddensity4_CODN_wz =std(oddensity4_CODN_w)
egen oddensity4_CODNl1_wz =std(oddensity4_CODNl1_w)
egen oddensity4_ODNOTHER_wz =std(oddensity4_ODNOTHER_w)
egen oddensity4_ODNOTHERl1_wz =std(oddensity4_ODNOTHERl1_w)
egen odfocal4_wz =std(odfocal4_w)
egen odfocal4l1_wz =std(odfocal4l1_w)
egen popoddensity4_wz =std(popoddensity4_w)
egen popoddensity4l1_wz =std(popoddensity4l1_w)
egen xrd2at_wz =std(xrd2at_w)
egen numpat2at_wz =std(numpat2at_w)
egen valpat2at_wz =std(valpat2at_w)
egen profitability_wz =std(profitability_w)
egen mkt_book_wz =std(mkt_book_w)
egen mkt_bookf1_wz =std(mkt_bookf1_w)
egen prodmktfluid_z =std(prodmktfluid)
egen prodmktfluid_wz =std(prodmktfluid_w)
egen tsim4_wz =std(tsim4_w)

*******************************************************************************
* COW
bys year: egen COWpct50l1 = pctile(COWtn4l1_w) if COWtn4l1_w!=. , p(50)
gen highCOWl1=.
replace highCOWl1=0 if COWtn4l1_w<COWpct50l1 & COWtn4l1_w!=. 
replace highCOWl1=1 if COWtn4l1_w>=COWpct50l1 & COWtn4l1_w!=. 
replace highCOWl1=0 if COWtn4l1_w==0  

*******************************************************************************
* ISS Rule
bys year: egen ISSpct50 = pctile(ISStreattn4) if ISStreattn4!=. , p(50)
gen highISS=.
replace highISS=0 if ISStreattn4<=ISSpct50 & ISStreattn4!=. 
replace highISS=1 if ISStreattn4>ISSpct50 & ISStreattn4!=. 
gen highISS03=highISS if year==2003
sort gvkey highISS03
replace highISS03=highISS03[_n-1] if highISS03==. & highISS03[_n-1]!=.
gen ISStreattn42003=ISStreattn4_w if year==2003
sort gvkey ISStreattn42003
replace ISStreattn42003=ISStreattn42003[_n-1] if ISStreattn42003==. & ISStreattn42003[_n-1]!=.

*******************************************************************************
*******************************************************************************

* TABLE 1: 

* sutex2  oddensity4l1_w oddensity2_4l1_w  popoddensity4l1_w  odfocal4l1_w   odn_connectionl1 codn_connectionl1  xrd2at_w numpat2at_w valpat2at_w  tsim4_w prodmktfluid_w profitability_w mkt_book_w  log_atl1_w log_agel1_w  if year>=1989  & year<=2018 & oddensity4l1_wz!=. &  xrd2at_w!=. &  numpat2at_w!=. &  valpat2at_w!=. &   tsim4_w!=. &  prodmktfluid_w!=. &  profitability_w!=. &  mkt_book_w!=. & log_atl1_w!=. & log_agel1_w!=.  , percentiles(50) minmax varlabels saving(sumstats.tex) replace



*******************************************************************************
* TABLE 2: 

* corrtex  oddensity4_w  popoddensity4_w odfocal4_w  xrd2at_w numpat2at_w valpat2at_w  tsim4_w prodmktfluid_w profitability_w mkt_book_w   if year>=1989  & year<=2018 & oddensity4l1_wz!=. & log_atl1_w!=. & log_agel1_w!=. , file(correlations.tex) title("Correlations") replace



*******************************************************************************
* TABLE 3:  

* fixed effects: gvkey year
* cluster: (4-digit SIC code)x(year) gvkey
* controls: assets (lagged) + age (lagged)
* sample period: 1989-2018

* Panel A: 
**********************************************************
reghdfe tsim4_wz oddensity4l1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe profitability_wz oddensity4l1_wz  log_atl1_w log_agel1_w if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe mkt_book_wz oddensity4l1_wz  log_atl1_w log_agel1_w if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe xrd2at_wz oddensity4l1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe numpat2at_wz oddensity4l1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe valpat2at_wz oddensity4l1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe prodmktfluid_wz oddensity4l1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)
   

* Panel B: 
******************************************************************
reghdfe tsim4_wz oddensity4_ODNl1_wz  log_atl1_w log_agel1_w if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe profitability_wz oddensity4_ODNl1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe mkt_book_wz oddensity4_ODNl1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe xrd2at_wz oddensity4_ODNl1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe numpat2at_wz oddensity4_ODNl1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe valpat2at_wz oddensity4_ODNl1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe prodmktfluid_wz oddensity4_ODNl1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)


* Panel C: 
******************************************************************
reghdfe tsim4_wz oddensity4_CODNl1_wz  log_atl1_w log_agel1_w if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe profitability_wz oddensity4_CODNl1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe mkt_book_wz oddensity4_CODNl1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe xrd2at_wz oddensity4_CODNl1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe numpat2at_wz oddensity4_CODNl1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe valpat2at_wz oddensity4_CODNl1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe prodmktfluid_wz oddensity4_CODNl1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)
   
 
* Panel D: 
******************************************************************
reghdfe tsim4_wz oddensity4_ODNOTHERl1_wz  log_atl1_w log_agel1_w if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe profitability_wz oddensity4_ODNOTHERl1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe mkt_book_wz oddensity4_ODNOTHERl1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe xrd2at_wz oddensity4_ODNOTHERl1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe numpat2at_wz oddensity4_ODNOTHERl1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe valpat2at_wz oddensity4_ODNOTHERl1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe prodmktfluid_wz oddensity4_ODNOTHERl1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)



*******************************************************************************
* TABLE 4:  

* fixed effects: gvkey year
* cluster: (4-digit SIC code)x(year) gvkey
* controls: assets (lagged) + age (lagged)
* sample period: 1989-2018

reghdfe tsim4_wz  oddensity2_4l1_wz oddensity4l1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe profitability_wz oddensity2_4l1_wz oddensity4l1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe mkt_book_wz oddensity2_4l1_wz oddensity4l1_wz  log_atl1_w log_agel1_w  if year>=1989 & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe xrd2at_wz oddensity2_4l1_wz oddensity4l1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe numpat2at_wz oddensity2_4l1_wz oddensity4l1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe valpat2at_wz oddensity2_4l1_wz oddensity4l1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe prodmktfluid_wz oddensity2_4l1_wz oddensity4l1_wz  log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)


*******************************************************************************
* TABLE 5:  

* fixed effects: gvkey year
* cluster: (4-digit SIC code)x(year) gvkey
* controls: assets (lagged) + age (lagged)
* sample period: 1989-2018

gen z2=ISStreattn42003
egen z2s=std(z2)
replace z2=z2s
gen post2004=0
replace post2004=1 if year>2004
tostring year, generate(year_s)
tostring sic, generate(sic_s)
gen sic_x_year=sic_s+year_s
drop year_s

* First stage
reghdfe oddensity4l1_wz  c.z2#c.post2004  log_atl1 log_agel1  if year>=2000 & year<=2009 & tsim4_wz!=. & profitability_wz!=. & mkt_book_wz!=. & numpat2at_wz!=. & valpat2at_wz!=. & prodmktfluid_wz!=. , absorb(gvkey year ) cluster(sic#year gvkey)

* Second stage
ivreghdfe  tsim4_wz     (oddensity4l1_wz =   c.z2#c.post2004  log_atl1 log_agel1    ) if year>=2000 & year<=2009 & tsim4_wz!=. & profitability_wz!=. & mkt_book_wz!=. & numpat2at_wz!=. & valpat2at_wz!=. & prodmktfluid_wz!=. , absorb(gvkey year ) cluster(sic_x_year gvkey) first

ivreghdfe  profitability_w      (oddensity4l1_wz =   c.z2#c.post2004  log_atl1 log_agel1     ) if year>=2000 & year<=2009   & tsim4_wz!=. & profitability_wz!=. & mkt_book_wz!=. & numpat2at_wz!=. & valpat2at_wz!=. & prodmktfluid_wz!=. , absorb(gvkey year ) cluster(sic_x_year gvkey) 

ivreghdfe  mkt_book_wz    (oddensity4l1_wz =   c.z2#c.post2004  log_atl1 log_agel1     ) if year>=2000 & year<=2009   & tsim4_wz!=. & profitability_wz!=. & mkt_book_wz!=. & numpat2at_wz!=. & valpat2at_wz!=. & prodmktfluid_wz!=. , absorb(gvkey year ) cluster(sic_x_year gvkey) 

ivreghdfe  xrd2at_wz      (oddensity4l1_wz =   c.z2#c.post2004  log_atl1 log_agel1    ) if year>=2000 & year<=2009   & tsim4_wz!=. & profitability_wz!=. & mkt_book_wz!=. & numpat2at_wz!=. & valpat2at_wz!=. & prodmktfluid_wz!=. , absorb(gvkey year ) cluster(sic_x_year gvkey) 

ivreghdfe  numpat2at_wz        (oddensity4l1_wz =   c.z2#c.post2004  log_atl1 log_agel1     ) if year>=2000 & year<=2009   & tsim4_wz!=. & profitability_wz!=. & mkt_book_wz!=. & numpat2at_wz!=. & valpat2at_wz!=. & prodmktfluid_wz!=. , absorb(gvkey year ) cluster(sic_x_year gvkey) 

ivreghdfe  valpat2at_wz      (oddensity4l1_wz =   c.z2#c.post2004  log_atl1 log_agel1     ) if year>=2000 & year<=2009   & tsim4_wz!=. & profitability_wz!=. & mkt_book_wz!=. & numpat2at_wz!=. & valpat2at_wz!=. & prodmktfluid_wz!=. , absorb(gvkey year ) cluster(sic_x_year gvkey) 

ivreghdfe  prodmktfluid_wz      (oddensity4l1_wz =   c.z2#c.post2004  log_atl1 log_agel1     ) if year>=2000 & year<=2009   & tsim4_wz!=. & profitability_wz!=. & mkt_book_wz!=. & numpat2at_wz!=. & valpat2at_wz!=. & prodmktfluid_wz!=. , absorb(gvkey year ) cluster(sic_x_year gvkey) 



*******************************************************************************
* TABLE 6:  

/*
Delaware July 1, 2000
Oklahoma November 1, 2001
Missouri October 1, 2003
Kansas January 1, 2005
Texas January 1, 2006
Nevada October 1, 2007
New Jersey March 11, 2011
Maryland October 1, 2014
Washington January 1, 2016
*/



*******************************************************************************
* TABLE 7: 

* fixed effects: gvkey year
* cluster: (4-digit SIC code)x(year) gvkey
* controls: assets (lagged) + age (lagged)
* sample period: 1989-2018

reghdfe tsim4_wz oddensity4l1_wz  c.oddensity4l1_wz#i.highCOWl1 highCOWl1 log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe profitability_wz oddensity4l1_wz  c.oddensity4l1_wz#i.highCOWl1 highCOWl1 log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe mkt_book_wz oddensity4l1_wz  c.oddensity4l1_wz#i.highCOWl1 highCOWl1 log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe xrd2at_wz oddensity4l1_wz c.oddensity4l1_wz#i.highCOWl1 highCOWl1 log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe numpat2at_wz oddensity4l1_wz  c.oddensity4l1_wz#i.highCOWl1 highCOWl1 log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe valpat2at_wz oddensity4l1_wz  c.oddensity4l1_wz#i.highCOWl1 highCOWl1 log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)

reghdfe prodmktfluid_wz oddensity4l1_wz  c.oddensity4l1_wz#i.highCOWl1 highCOWl1 log_atl1_w log_agel1_w  if year>=1989  & year<=2018, absorb(gvkey year ) cluster(sic#year gvkey)




*******************************************************************************
* FIGURE 3

gen year_1990=0
gen year_1991=0
gen year_1992=0
gen year_1993=0
gen year_1994=0
gen year_1995=0
gen year_1996=0
gen year_1997=0
gen year_1998=0
gen year_1999=0
gen year_2000=0
gen year_2001=0
gen year_2002=0
gen year_2003=0
gen year_2004=0
gen year_2005=0
gen year_2006=0
gen year_2007=0
gen year_2008=0
gen year_2009=0
gen year_2010=0
gen year_2011=0
gen year_2012=0
gen year_2013=0
gen year_2014=0
gen year_2015=0
gen year_2016=0
gen year_2017=0
gen year_2018=0
gen year_2019=0
gen year_2020=0
replace year_1990=1 if year==1990
replace year_1991=1 if year==1991
replace year_1992=1 if year==1992
replace year_1993=1 if year==1993
replace year_1994=1 if year==1994
replace year_1995=1 if year==1995
replace year_1996=1 if year==1996
replace year_1997=1 if year==1997
replace year_1998=1 if year==1998
replace year_1999=1 if year==1999
replace year_2000=1 if year==2000
replace year_2001=1 if year==2001
replace year_2002=1 if year==2002
replace year_2003=1 if year==2003
replace year_2004=1 if year==2004
replace year_2005=1 if year==2005
replace year_2006=1 if year==2006
replace year_2007=1 if year==2007
replace year_2008=1 if year==2008
replace year_2009=1 if year==2009
replace year_2010=1 if year==2010
replace year_2011=1 if year==2011
replace year_2012=1 if year==2012
replace year_2013=1 if year==2013
replace year_2014=1 if year==2014
replace year_2015=1 if year==2015
replace year_2016=1 if year==2016
replace year_2017=1 if year==2017
replace year_2018=1 if year==2018
replace year_2019=1 if year==2019
replace year_2020=1 if year==2020

reghdfe oddensity4_w z2  c.z2#c.year_*  i.year_*  log_atl1 log_agel1  if year>=1999 & year<=2008 , absorb(gvkey  ) cluster(gvkey) 


*******************************************************************************
* FIGURE 4
sort year
winsor2  oddensity4_bin* , cuts(5 95) by(year)
sort gvkey year

* Figure (a): 
reghdfe tsim4_wz   oddensity4_bin100_w oddensity4_bin30_w oddensity4_bin29_w oddensity4_bin28_w oddensity4_bin27_w oddensity4_bin26_w oddensity4_bin25_w oddensity4_bin24_w oddensity4_bin23_w oddensity4_bin22_w oddensity4_bin21_w oddensity4_bin20_w oddensity4_bin19_w oddensity4_bin18_w oddensity4_bin17_w oddensity4_bin16_w oddensity4_bin15_w oddensity4_bin14_w oddensity4_bin13_w oddensity4_bin12_w oddensity4_bin11_w oddensity4_bin10_w oddensity4_bin9_w oddensity4_bin8_w oddensity4_bin7_w oddensity4_bin6_w oddensity4_bin5_w oddensity4_bin4_w oddensity4_bin3_w oddensity4_bin2_w oddensity4_bin1_w oddensity4_bin0_w oddensity4_bin_1_w oddensity4_bin_2_w oddensity4_bin_3_w oddensity4_bin_4_w oddensity4_bin_5_w oddensity4_bin_6_w oddensity4_bin_7_w oddensity4_bin_8_w oddensity4_bin_9_w oddensity4_bin_10_w oddensity4_bin_11_w oddensity4_bin_12_w oddensity4_bin_13_w oddensity4_bin_14_w oddensity4_bin_15_w oddensity4_bin_16_w oddensity4_bin_17_w oddensity4_bin_18_w oddensity4_bin_19_w oddensity4_bin_20_w oddensity4_bin_21_w oddensity4_bin_22_w oddensity4_bin_23_w oddensity4_bin_24_w oddensity4_bin_25_w oddensity4_bin_26_w oddensity4_bin_27_w oddensity4_bin_28_w oddensity4_bin_29_w oddensity4_bin_30_w  log_atl1_w log_agel1_w  , absorb(gvkey year ) cluster(gvkey)
* Figure (b): 
reghdfe profitability_wz   oddensity4_bin100_w oddensity4_bin30_w oddensity4_bin29_w oddensity4_bin28_w oddensity4_bin27_w oddensity4_bin26_w oddensity4_bin25_w oddensity4_bin24_w oddensity4_bin23_w oddensity4_bin22_w oddensity4_bin21_w oddensity4_bin20_w oddensity4_bin19_w oddensity4_bin18_w oddensity4_bin17_w oddensity4_bin16_w oddensity4_bin15_w oddensity4_bin14_w oddensity4_bin13_w oddensity4_bin12_w oddensity4_bin11_w oddensity4_bin10_w oddensity4_bin9_w oddensity4_bin8_w oddensity4_bin7_w oddensity4_bin6_w oddensity4_bin5_w oddensity4_bin4_w oddensity4_bin3_w oddensity4_bin2_w oddensity4_bin1_w oddensity4_bin0_w oddensity4_bin_1_w oddensity4_bin_2_w oddensity4_bin_3_w oddensity4_bin_4_w oddensity4_bin_5_w oddensity4_bin_6_w oddensity4_bin_7_w oddensity4_bin_8_w oddensity4_bin_9_w oddensity4_bin_10_w oddensity4_bin_11_w oddensity4_bin_12_w oddensity4_bin_13_w oddensity4_bin_14_w oddensity4_bin_15_w oddensity4_bin_16_w oddensity4_bin_17_w oddensity4_bin_18_w oddensity4_bin_19_w oddensity4_bin_20_w oddensity4_bin_21_w oddensity4_bin_22_w oddensity4_bin_23_w oddensity4_bin_24_w oddensity4_bin_25_w oddensity4_bin_26_w oddensity4_bin_27_w oddensity4_bin_28_w oddensity4_bin_29_w oddensity4_bin_30_w  log_atl1_w log_agel1_w  , absorb(gvkey year ) cluster(gvkey)
* Figure (c): 
reghdfe mkt_bookf1_wz  oddensity4_bin100_w oddensity4_bin30_w oddensity4_bin29_w oddensity4_bin28_w oddensity4_bin27_w oddensity4_bin26_w oddensity4_bin25_w oddensity4_bin24_w oddensity4_bin23_w oddensity4_bin22_w oddensity4_bin21_w oddensity4_bin20_w oddensity4_bin19_w oddensity4_bin18_w oddensity4_bin17_w oddensity4_bin16_w oddensity4_bin15_w oddensity4_bin14_w oddensity4_bin13_w oddensity4_bin12_w oddensity4_bin11_w oddensity4_bin10_w oddensity4_bin9_w oddensity4_bin8_w oddensity4_bin7_w oddensity4_bin6_w oddensity4_bin5_w oddensity4_bin4_w oddensity4_bin3_w oddensity4_bin2_w oddensity4_bin1_w oddensity4_bin0_w oddensity4_bin_1_w oddensity4_bin_2_w oddensity4_bin_3_w oddensity4_bin_4_w oddensity4_bin_5_w oddensity4_bin_6_w oddensity4_bin_7_w oddensity4_bin_8_w oddensity4_bin_9_w oddensity4_bin_10_w oddensity4_bin_11_w oddensity4_bin_12_w oddensity4_bin_13_w oddensity4_bin_14_w oddensity4_bin_15_w oddensity4_bin_16_w oddensity4_bin_17_w oddensity4_bin_18_w oddensity4_bin_19_w oddensity4_bin_20_w oddensity4_bin_21_w oddensity4_bin_22_w oddensity4_bin_23_w oddensity4_bin_24_w oddensity4_bin_25_w oddensity4_bin_26_w oddensity4_bin_27_w oddensity4_bin_28_w oddensity4_bin_29_w oddensity4_bin_30_w log_atl1_w log_agel1_w , absorb(gvkey year ) cluster(gvkey)
* Figure (d): 
reghdfe xrd2at_wz   oddensity4_bin100_w oddensity4_bin30_w oddensity4_bin29_w oddensity4_bin28_w oddensity4_bin27_w oddensity4_bin26_w oddensity4_bin25_w oddensity4_bin24_w oddensity4_bin23_w oddensity4_bin22_w oddensity4_bin21_w oddensity4_bin20_w oddensity4_bin19_w oddensity4_bin18_w oddensity4_bin17_w oddensity4_bin16_w oddensity4_bin15_w oddensity4_bin14_w oddensity4_bin13_w oddensity4_bin12_w oddensity4_bin11_w oddensity4_bin10_w oddensity4_bin9_w oddensity4_bin8_w oddensity4_bin7_w oddensity4_bin6_w oddensity4_bin5_w oddensity4_bin4_w oddensity4_bin3_w oddensity4_bin2_w oddensity4_bin1_w oddensity4_bin0_w oddensity4_bin_1_w oddensity4_bin_2_w oddensity4_bin_3_w oddensity4_bin_4_w oddensity4_bin_5_w oddensity4_bin_6_w oddensity4_bin_7_w oddensity4_bin_8_w oddensity4_bin_9_w oddensity4_bin_10_w oddensity4_bin_11_w oddensity4_bin_12_w oddensity4_bin_13_w oddensity4_bin_14_w oddensity4_bin_15_w oddensity4_bin_16_w oddensity4_bin_17_w oddensity4_bin_18_w oddensity4_bin_19_w oddensity4_bin_20_w oddensity4_bin_21_w oddensity4_bin_22_w oddensity4_bin_23_w oddensity4_bin_24_w oddensity4_bin_25_w oddensity4_bin_26_w oddensity4_bin_27_w oddensity4_bin_28_w oddensity4_bin_29_w oddensity4_bin_30_w log_atl1_w log_agel1_w   , absorb(gvkey year ) cluster(gvkey)
* Figure (e): 
reghdfe valpat2at_wz   oddensity4_bin100_w oddensity4_bin30_w oddensity4_bin29_w oddensity4_bin28_w oddensity4_bin27_w oddensity4_bin26_w oddensity4_bin25_w oddensity4_bin24_w oddensity4_bin23_w oddensity4_bin22_w oddensity4_bin21_w oddensity4_bin20_w oddensity4_bin19_w oddensity4_bin18_w oddensity4_bin17_w oddensity4_bin16_w oddensity4_bin15_w oddensity4_bin14_w oddensity4_bin13_w oddensity4_bin12_w oddensity4_bin11_w oddensity4_bin10_w oddensity4_bin9_w oddensity4_bin8_w oddensity4_bin7_w oddensity4_bin6_w oddensity4_bin5_w oddensity4_bin4_w oddensity4_bin3_w oddensity4_bin2_w oddensity4_bin1_w oddensity4_bin0_w oddensity4_bin_1_w oddensity4_bin_2_w oddensity4_bin_3_w oddensity4_bin_4_w oddensity4_bin_5_w oddensity4_bin_6_w oddensity4_bin_7_w oddensity4_bin_8_w oddensity4_bin_9_w oddensity4_bin_10_w oddensity4_bin_11_w oddensity4_bin_12_w oddensity4_bin_13_w oddensity4_bin_14_w oddensity4_bin_15_w oddensity4_bin_16_w oddensity4_bin_17_w oddensity4_bin_18_w oddensity4_bin_19_w oddensity4_bin_20_w oddensity4_bin_21_w oddensity4_bin_22_w oddensity4_bin_23_w oddensity4_bin_24_w oddensity4_bin_25_w oddensity4_bin_26_w oddensity4_bin_27_w oddensity4_bin_28_w oddensity4_bin_29_w oddensity4_bin_30_w  log_atl1_w log_agel1_w  , absorb(gvkey year ) cluster(gvkey)



*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*




